home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 21 / Cream of the Crop 21 (Terry Blount) (October 1996).iso / bbs / tg_os2.zip / PHONEV41.ZIP / PHONEV4.ASM next >
Assembly Source File  |  1990-08-20  |  15KB  |  536 lines

  1. ;        Phone monitor - CFHSoftware
  2. ;
  3. ;
  4. ;     To Assemble:
  5. ;
  6. ;     MASM PHONE;
  7. ;     LINK PHONE;
  8. ;     EXE2BIN PHONE.EXE PHONE.COM
  9. ;
  10. ;
  11. ;       THIS PROGRAM >MUST< BE RUN AS A .COM FILE
  12. ;
  13. ;
  14. MS_DOS  EQU     21H
  15. MOD_STA EQU     6                       ; Offset to 8250 modem-status port
  16. RI      EQU     01000000B               ; Ring indicator
  17. RLSD    EQU     10000000B               ; Received line signal det
  18.  
  19. BOOT_BLIND      MACRO
  20.         MOV     AX,0FFFFH               ; Segment of boot code
  21.         PUSH    AX                      ; Push on the stack
  22.         INC     AX                      ; Make ax=0 (offset of boot code)
  23.         PUSH    AX                      ; Push on the stack
  24.         RETF                            ; Far 'return' to boot code
  25. ENDM
  26.  
  27. PSEG    SEGMENT PARA PUBLIC 'CODE'
  28. BEGIN   EQU     $
  29.         ASSUME  CS:PSEG, DS:PSEG, ES:PSEG, SS:NOTHING
  30.         ORG     100H
  31. MAIN    PROC    NEAR
  32. START   EQU     $
  33.  
  34. STK_TOP LABEL   WORD                    ; Where to start local stack
  35.         JMP     INIT1
  36. MAIN    ENDP
  37. ;
  38. signature       db "CFH"
  39. OLD_INT LABEL   DWORD                   ; Old int 8
  40. OLD_OFF DW      ?                       ; Int 8 offset
  41. OLD_SEG DW      ?                       ; Int 8 segment
  42.  
  43. old_49  label   dword
  44. old_49_off dw   ?
  45. old_49_seg dw   ?
  46.  
  47. RINGS   DB      0
  48. TRIGGER DB      9
  49. LASTRNG DB      ?
  50. LASTCAR DB      ?
  51. tone    dw      10010
  52.  
  53. CHK_PRT DW      0
  54. SS_SAV  DW      ?
  55. SP_SAV  DW      ?
  56. BUSY    DB      0
  57. SOUND   db      0
  58. PSP     dw      0
  59.  
  60. CHANGE_TRIGGER PROC FAR
  61.         PUSH    DS
  62.  
  63.         PUSH    CS
  64.         POP     DS
  65.  
  66.         cmp     ax, 69h
  67.         jnz     nope
  68.         cmp     cx, 69h
  69.         jnz     nope
  70.  
  71.         MOV     BYTE PTR [RINGS], 0
  72.         MOV     BYTE PTR [TRIGGER], BL
  73.         MOV     AX, 1
  74.         MOV     BX, 2
  75.         MOV     CX, 3
  76.         MOV     DX, 4
  77.         POP     DS
  78.         IRET
  79. nope:
  80.         cmp     ax, "UN"
  81.         jne     not_mine
  82.         cmp     bx, "IN"
  83.         jne     not_mine
  84.         cmp     cx, "ST"
  85.         jne     not_mine
  86.         cmp     dx, "AL"
  87.         jne     not_mine
  88.         mov     bx, psp
  89.         mov     cx, cs
  90.  
  91.         MOV     AX,2508H                   ; Patch INT 8
  92.         MOV     DX, cs:old_off             ; DS:DX = new vector
  93.         MOV     DS, cs:old_seg
  94.         INT     MS_DOS
  95.  
  96.         MOV     AX, 2549h
  97.         MOV     DX, cs:old_49_off
  98.         MOV     DS, cs:old_49_seg
  99.         INT     MS_DOS
  100.  
  101.         pop     ds
  102.         IRET
  103. not_mine:
  104.         cmp     ax, "SO"
  105.         jne     nope2
  106.         cmp     bx, "UN"
  107.         jne     nope2
  108.         cmp     cx, "D!"
  109.         jne     nope2
  110.         xor     ah,ah
  111.         mov     al, byte ptr sound
  112.         xor     al,1
  113.         mov     byte ptr sound, al
  114.         POP     DS
  115.         IRET
  116. nope2:
  117.         pop     ds
  118.         jmp     dword ptr cs:[old_49]
  119. CHANGE_TRIGGER ENDP
  120.  
  121. ;
  122. ;       Check the modem status.
  123. ;
  124. CHK_MOD PROC    NEAR
  125.         PUSH    DX                      ; Save register used
  126.         MOV     DX,WORD PTR [CHK_PRT]   ; Pick up modem-status port
  127.         ADD     DX,MOD_STA
  128.         IN      AL,DX                   ; Get modem status
  129.         AND     AL,RI                   ; Check the bit
  130.         CMP     BYTE PTR [LASTRNG],AL   ; Same last time?
  131.         MOV     BYTE PTR [LASTRNG],AL   ; Set new status
  132.         JZ      NODETR                  ; Yes, ignore.
  133.         CMP     BYTE PTR [LASTRNG],0    ; Not ringing?
  134.         JNZ     @f
  135.         in      al, 61h
  136.         and     al, 11111100b
  137.         out     61h, al
  138.         jmp     nodetr
  139.  
  140.  
  141. @@:     INC     BYTE PTR [RINGS]        ; Number of rings
  142.         cmp     sound, 1                ;is noise allowed?
  143.         jne     nodetr                  ;if not, skip this stuff
  144.         mov     al, 182
  145.         out     43h, al
  146.         mov     ax, tone                ; ringer tone
  147.         sub     ax, 1000
  148.         mov     tone, ax
  149.         out     42h, al
  150.         mov     al, ah
  151.         out     42h, al
  152.         in      al, 61h
  153.         or      al, 3
  154.         out     61h, al
  155. ;
  156. NODETR:
  157.         CMP     BYTE PTR [LASTRNG],0    ; Not ringing?
  158.         MOV     DX,WORD PTR [CHK_PRT]   ; Pick up modem-status port
  159.         ADD     DX,MOD_STA
  160.         IN      AL,DX                   ; Get modem status
  161.         AND     AL,RLSD                 ; Check the bit
  162.         MOV     BYTE PTR [LASTCAR],AL   ; Set new status
  163.         CMP     BYTE PTR [LASTCAR],0    ; See if the carrier is off
  164.         JZ      CAROFF                  ; Yes it is.
  165.         MOV     BYTE PTR [RINGS],0      ; Carrier's on, zero the ring-count
  166.         mov     word ptr [tone], 9010   ;  and the tone
  167. CAROFF: POP     DX                      ; Restore registers used
  168.         RET
  169. CHK_MOD ENDP
  170. ;
  171. ;       Main Interrupt routine. This is patched to the clock interrupt at
  172. ;       INT 08. After checking, it continues to main DOS routines.
  173. ;
  174. INTER   PROC    FAR
  175.         CMP     BYTE PTR CS:[TRIGGER],0 ;see if we are disabled
  176.         JZ      @F
  177.         CMP     BYTE PTR CS:[BUSY],0    ; See if we are re-entering
  178.         JZ      NOBUSY                  ; No.
  179. @@:     JMP     DWORD PTR CS:[OLD_int]  ; Continue to old vector
  180. ;
  181. NOBUSY: MOV     BYTE PTR CS:[BUSY],0FFH ; Set busy flag
  182.         CLI
  183.         MOV     WORD PTR CS:[SS_SAV],SS ; Save stack-segment
  184.         MOV     WORD PTR CS:[SP_SAV],SP ; Save stack-pointer
  185.         PUSH    CS
  186.         POP     SS                      ; SS = CS
  187.         MOV     SP,OFFSET STK_TOP       ; Set up local stack
  188.         STI                             ; Allow interrupts
  189. ;
  190.         PUSH    AX                      ; Free up a working register
  191.         PUSH    DS                      ; Save data-segment
  192.  
  193.         PUSH    CS                      ; Establish addressability
  194.         POP     DS                      ; DS = CS
  195.  
  196.         CALL    CHK_MOD
  197.         MOV     AL, BYTE PTR [TRIGGER]
  198.         CMP     BYTE PTR CS:[RINGS], AL ; modem rings > AL ? <<<<<<<<<<<<<<
  199.         JG      CRASH                   ; Yes, crash the system.
  200.         POP     DS
  201.         POP     AX
  202.         CLI                             ; No interrupts
  203.         MOV     SS,WORD PTR CS:[SS_SAV] ; Restore user stack
  204.         MOV     SP,WORD PTR CS:[SP_SAV]
  205.         MOV     BYTE PTR CS:[BUSY],0    ; Free up busy-flag
  206.         STI                             ; Allow interrupts
  207.         JMP     DWORD PTR CS:[OLD_INT]  ; Continue to old vector
  208. CRASH:
  209.         BOOT_BLIND
  210. INTER  ENDP
  211.  
  212. TOP     EQU     $
  213. ;
  214. ;       Iniitialization code. This space is used only once then given up.
  215. ;
  216.  
  217. ; get_args
  218. ; gets the command line information from the psp
  219. ;ENTRY:
  220. ;     di points to a 127 byte buffer into which you want the command line
  221. ;        info copied.
  222. ;EXIT:
  223. ;     cx contains the number of characters on the command line
  224. ;     di points to the "buffer" area into which the info was copied
  225. ;     all other registers' previous values ARE preserved (i.e. not destroyed)
  226. get_args proc
  227.         push ax
  228.         push bx
  229.         push di
  230.         push si
  231.         push ds
  232.         mov ah, 62h
  233.         int 21h
  234.         push bx
  235.         mov cs:psp, bx
  236.         pop ds
  237.         mov si, 80h
  238.         lodsb
  239.         xor ch, ch
  240.         mov cl, al
  241.         push cx
  242.         rep movsb
  243.         pop cx
  244.         pop ds
  245.         pop si
  246.         pop di
  247.         pop bx
  248.         pop ax
  249.         ret
  250. get_args endp
  251.  
  252. ;Extract_args
  253. ;
  254. ;Searches for a '/' delimiter in arguments string followed by whatever
  255. ;character is sent in al, returns with di pointing to the first character
  256. ;following the character specified
  257. ;
  258. ;Entry: di - point to beginning of argument string
  259. ;       al - contains character which follows the '/' delimiter
  260. ;
  261. ;Exit:  CF set   - not found
  262. ;       CF clear - found
  263. ;                  di points to first char in arg string following
  264. ;                  /char 
  265. extract_args proc
  266.         mov cx, 127
  267. topside:
  268.         jcxz notfound
  269.         push ax
  270.         mov ax, "/"
  271.         repne scasb
  272.         pop ax
  273.         jnz topside
  274. got_slash:
  275.         scasb
  276.         jnz topside
  277. found_it:
  278.         clc
  279.         ret
  280. notf